package com.ray.aopdemo.aopdemo2;

import com.ray.aopdemo.aopdemo1.ManWaiter;
import com.ray.aopdemo.aopdemo1.Waiter;

/**
 * User: Ray.Shaw <p />
 * Time: 2019/11/1 14:43  <p />
 * Version: V1.0  <p />
 * Description: https://www.jianshu.com/p/aaeb2355ec5c <p />
 */
public class TestProxyAopFactory {
    public static void main(String[] args) {
        new TestProxyAopFactory().test();
    }

    public void test() {
        //创建工厂
        ProxyFactory proxyFactory = new ProxyFactory();
        //设置目标对象
        proxyFactory.setTargetObject(new ManWaiter());

        //设置前置增强
        proxyFactory.setBeforeAdvice(new BeforeAdvice() {
            @Override
            public void before() {
                System.out.println("客户你好");
            }
        });

        //设置后置增强
        proxyFactory.setAfterAdvice(new AfterAdvice() {
            @Override
            public void after() {
                System.out.println("客户再见");
            }
        });

        Waiter waiter = (Waiter) proxyFactory.creatProxy();
        waiter.server();
    }
}
